<script setup>
import { getArtistAlbum } from "../../../apis/user";
import { ref } from "vue";
import { useRoute } from "vue-router";
import { createWindow } from "../../../utils/ipcRenderer";
const route = useRoute();

const albumList = ref();

const getInit = () => {
  getArtistAlbum({ id: route.query.id, limit: 12 }).then((res) => {
    albumList.value = res.hotAlbums.slice(0, 20);
  });
};
getInit();

const handleAlbum = (id) => {
  createWindow({
    windowName: "albumDetail",
    path: "albumDetail",
    width: 1200,
    height: 820,
    param: { id: id },
  });
};
</script>

<template>
  <div class="singer_album">
    <div class="content_wrap">
      <div v-if="albumList" class="content">
        <div
          v-for="(item, index) in albumList"
          :key="index"
          style="position: relative"
          class="image"
        >
          <div @click="handleAlbum(item.id)" class="image_wrap">
            <el-image
              fit="cover"
              lazy
              :src="item.picUrl ? item.picUrl+`${'?param=200y200'}}`  : item.coverImgUrl+`${'?param=200y200'}}` "
            >
              <template #placeholder>
                <div class="image-slot">
                  Loading<span class="dot">...</span>
                </div>
              </template>
            </el-image>
          </div>

          <span class="name">{{ item.name }}</span>
          <span>{{ item.artist.name }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
.singer_album {
  .content_wrap {
    position: relative;
    margin-top: 30px;
    .el-zoom-in-top-enter-active {
      transition: all 0.5s;
    }
    .el-zoom-in-top-leave-active {
      transition: all 0.5s;
    }
    .show_name {
      // padding: 20px 30px;
      position: absolute;
      width: 100%;
      height: 480px;
      background-color: #f5f5f7;
      z-index: 99;
      border-radius: 10px;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      cursor: pointer;
      .show_name_wrap {
        padding: 20px 30px;
        display: flex;
        .category_title {
          width: 60px;
          font-size: 22px;
          font-weight: 600;
          color: #4f4f4f;
        }
        .name_wrap {
          flex: 1;
          display: flex;
          flex-wrap: wrap;
          .name_list {
            font-size: 17px;
            color: #333333;
            text-align: left;
            padding: 5px 15px;
            border-radius: 10px;
            margin-bottom: 10px;
            &:hover {
              background-color: #eaeffd;
              color: #335eea;
            }
          }
          .active {
            color: #335eea;
            background-color: #eaeffd;
          }
        }
      }
    }
    .content {
      // display: flex;
      // flex-wrap: wrap;
      display: grid;
      justify-content: space-around;
      grid-template-columns: repeat(auto-fill, 16vw);
      .image {
        margin-bottom: 45px;
        .image_wrap {
          position: relative;
          //   height: 17rem;
          // width: 15vw;
          // aspect-ratio: 1/1;
          .el-image {
            height: 100%;
            border-radius: 10px;
            transition: all 0.3s;
          }
          .el-image:hover {
            transform: translateY(-8px);
          }
        }
      }
      .image:hover .play_img {
        display: block;
      }
      .name {
        display: block;
        font-size: 16px;
        font-weight: 600;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
      }
    }
    .more {
      font-size: 18px;
      font-weight: 600;
      display: flex;
      justify-content: center;
      align-items: center;
      div {
        cursor: pointer;
        background-color: #f7f7f9;
        padding: 10px 20px;
        color: #393939;
        border-radius: 10px;
        transition: 0.5s;
        &:active {
          transform: scale(1.1);
        }
      }
    }
  }
}
</style>
